package io.r2mo.test.common;

import io.r2mo.spring.junit5.AppBaseTestSupport;
import io.r2mo.test.common.domain.OrderEntity;
import io.r2mo.typed.json.JObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lang : 2025-09-06
 */
@SpringBootTest(classes = TestCommonApplication.class)
@Transactional
@TestPropertySource("classpath:env-test.properties")
@Component
@Slf4j
public class IoReaderActTestCase extends AppBaseTestSupport<OrderEntity> {
    @Test
    public void testInJson() {
        final String testFile = "HFS/file/content.json";
        final JObject jsonObj = this.fs().inJson(testFile);
        log.info("[ R2MO ] (0) testInJson / 读取文件内容：\n{} ", jsonObj.encodePretty());
        Assertions.assertTrue(jsonObj.containsKey("name"));
    }

    @Test
    public void testInYaml() {
        final String testFile = "HFS/file/content.yml";
        final JObject jsonObj = this.fs().inYaml(testFile);
        log.info("[ R2MO ] (1) testInYaml / 读取文件内容：\n{} ", jsonObj.encodePretty());
        Assertions.assertTrue(jsonObj.containsKey("server"));
    }

    @Test
    public void testToYaml() {
        // 测试将 JBase 转换成 Yaml 的字符串写入到文件
        final String testFile = "HFS/file/content.yml";
        final JObject jsonObj = this.fs().inYaml(testFile);
        log.info("[ R2MO ] (2) testToYaml / 测试文件输出：\n{} ", jsonObj.encodeYaml());
    }
}
